package com.mscsoft.brainpower.server.service;

import javax.annotation.Resource;

import com.mscsoft.brainpower.server.dao.*;
import com.mscsoft.brainpower.server.domain.*;

import org.springframework.web.bind.annotation.RestController;

@RestController
public class DownloadService {
    @Resource
    MusicFileDao musicFileDao;
    @Resource
    MusicScoreFileDao musicScoreFileDao;
    @Resource
    ImageFileDao imageFileDao;

    public Msg<GameFile> download(String fileName, FileType fileType) {
        try {
            GameFile file = null;
            switch (fileType) {
                case Music:
                    file = musicFileDao.queryMusicFileByMusicName(fileName);
                    return new Msg<>(file);
                case MusicScore:
                    file = musicScoreFileDao.queryMusicScoreFileByMusicName(fileName);
                    return new Msg<>(file);
                case Image:
                    file = imageFileDao.queryImageFileByMusicName(fileName);
                    return new Msg<>(file);
                default:
                    return null;
            }
        } catch (Exception e) {
            return new Msg<>(500, Msg.s500);
        }
    }
}